package ce.com.cenewbluesdk.entity;

import java.util.Arrays;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.uitl.CRC16;

/**
 * Created by Administrator on 2016/11/8 0008.
 */
public class CEDevData implements Comparable<CEDevData> {
    int cmd;//命令类型
    int dataType;// 数据类型
    int itemL;// 数据中每个item的长度
    int itemNumber;// 数据中有几个item
    byte[] data;// 需要发送的数据
    byte[] otherData; // 这个是其他数据，可能需要发送蓝牙
    int dataCrc16;
    int currentIndex;
    int totalIndex;
    int N; //数据发送的流水号(0-255);


    public CEDevData() {
    }

    public CEDevData(int cmd, int dataType) {
        this.cmd = cmd;
        this.dataType = dataType;
    }

    protected int priority = CEBC.PRIORITY_NORMAL; // 优先级

    public int getCmd() {
        return cmd;
    }

    public void setCmd(int cmd) {
        this.cmd = cmd;
    }

    public int getDataType() {
        return dataType;
    }

    public void setDataType(int dataType) {
        this.dataType = dataType;
    }

    public int getItemL() {
        return itemL;
    }

    public void setItemL(int itemL) {
        this.itemL = itemL;
    }

    public int getItemNumber() {
        return itemNumber;
    }

    public void setItemNumber(int itemNumber) {
        this.itemNumber = itemNumber;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public byte[] getOtherData() {
        return otherData;
    }

    public void setOtherData(byte[] otherData) {
        this.otherData = otherData;
    }

    public int getDataCrc16() {
        return dataCrc16;
    }

    public void setDataCrc16(int dataCrc16) {
        this.dataCrc16 = dataCrc16;
    }

    public int figureCrc16() {
        int tCrc = 0;
        tCrc = CRC16.crc16(data);
        return tCrc;
    }


    public int getN() {
        return N;
    }

    public void setN(int n) {
        N = n;
    }

    public int getCurrentIndex() {
        return currentIndex;
    }

    public void setCurrentIndex(int currentIndex) {
        this.currentIndex = currentIndex;
    }

    public int getTotalIndex() {
        return totalIndex;
    }

    public void setTotalIndex(int totalIndex) {
        this.totalIndex = totalIndex;
    }

    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    @Override
    public int compareTo(CEDevData another) {
        if (this.priority > another.priority)
            return -1;
        else if (this.priority < another.priority)
            return 1;
        else
            return 0;
    }


    @Override
    public String toString() {
        return "CEDevData{" +
                "cmd=" + cmd +
                ", dataType=" + dataType +
                ", itemL=" + itemL +
                ", itemNumber=" + itemNumber +
                ", data=" + CEBC.byte2hex(data) +
                ", otherData=" + CEBC.byte2hex(otherData) +
                ", dataCrc16=" + dataCrc16 +
                ", currentIndex=" + currentIndex +
                ", totalIndex=" + totalIndex +
                ", priority=" + priority +
                '}';
    }
}
